package cn.maxhou.t0004.servlet;

import cn.maxhou.t0004.entity.UnsupportedTypeException;
import cn.maxhou.t0004.entity.User;
import cn.maxhou.t0004.util.SimpleBeanConvertor;

import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "test", value = "/test")
public class TestServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("utf-8");
        this.doGet(request, response);

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
            response.setCharacterEncoding("utf-8");
            try{
                // SimpleBeanconvertor.convert将请求req对象中的请求参数，
                // 在调用user实体类中的相关set方法后，赋值给User实体类中相关属性
                User user= SimpleBeanConvertor.convert(request, User.class);
                System.out.println(user);
            } catch (Exception e){
                e.printStackTrace();
            }
    }
}